const { toUrl,globalData } = getApp()
import { request } from "@/utils/request"
Page({
    toUrl,
    data: {
        form: {
            activity_id: '',
            realname: '',
            birthday: '',
            mobile: ''
        },
        detail: null,
        globalData
    },

    dateChange ({detail}) {
        const form = this.data.form
        form.birthday = detail.value
        this.setData({
            form: form
        })
    },
    getDetail(id) {
        const that = this
        const data = {
            activity_id: id
        }
        request('activity/activityinfo',{data}).then(res => {
            that.setData({
                detail: res.data
            })
        })
    },
    inputRealName(e) {
        const form = this.data.form
        form.realname = e.detail.value
        this.setData({
            form: form
        })
    },
    inputPhone(e) {
        const form = this.data.form
            form.mobile = e.detail.value
            this.setData({
                form: form
            })
        
    },
    applyActive() {
        const data = this.data.form
        request('activity/apply',{data}).then(res => {
            if(res.errcode == 1) {
                wx.navigateTo({
                  url: '/pages/activity/status',
                })
            }
        })
    },
    onLoad(options) {
        const id = options.active_id
        const form = this.data.form
        form.activity_id = id
        this.setData({
            form: form
        })
        this.getDetail(id)
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})